package com.stephenone.zhdaily.data.source.remote;

import android.support.annotation.NonNull;

import com.google.common.base.Optional;
import com.stephenone.zhdaily.data.api.ZhiHuDailyApiHelper;
import com.stephenone.zhdaily.data.bean.News;
import com.stephenone.zhdaily.data.source.NewsDataSource;
import com.stephenone.zhdaily.uitl.TimeUtil;

import org.reactivestreams.Subscriber;

import java.util.List;

import javax.annotation.Nonnull;

import io.reactivex.Flowable;

/**
 * Created by Administrator on 2018/3/5.
 */

public class NewsRemoteDataSource implements NewsDataSource {

    private static NewsRemoteDataSource INSTANCE;

    private NewsRemoteDataSource(){
    }

    public static NewsRemoteDataSource getInstance(){
        if (INSTANCE == null) {
            INSTANCE = new NewsRemoteDataSource();
        }
        return INSTANCE;
    }

    @Override
    public Flowable<List<News>> getNews() {
        return null;
    }

    @Override
    public Flowable<Optional<News>> getLatestNews() {
        return ZhiHuDailyApiHelper.sService.getLatestNews().map(news -> Optional.of(news));
    }

    @Override
    public Flowable<Optional<News>> getOneNews(@NonNull String date) {
        String currentDate = TimeUtil.afterThis(date);
        return ZhiHuDailyApiHelper.sService.getBeforeNews(currentDate).map(news -> Optional.of(news));
    }

    @Override
    public void refreshNews() {

    }

    @Override
    public void saveNews(@NonNull String date, @Nonnull News news) {

    }

}
